<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>欢迎页</title>
    <link rel="stylesheet" href="../../static/frame/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/frame/static/css/style.css">
    <link rel="icon" href="../../static/frame/static/image/code.png">
</head>
<body class="body">

<div class="layui-row layui-col-space10 my-index-main">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">拉黑应用</label>
            <div class="layui-input-block">
                <select id="applist" name="applist" lay-search required lay-verify="required">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">输入对象</label>
            <div class="layui-input-block">
                <input type="text" name="obj" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">输入理由</label>
            <div class="layui-input-block">
                <input type="text" name="reason" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">添加云黑</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>


    <table class="layui-hide" id="bclist" lay-filter="bclist"></table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
    </script>

</div>


<script src="../../static/jquery-3.3.1.js"></script>
<script type="text/javascript" src="../../static/frame/layui/layui.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script type="text/javascript" src="../../static/frame/echarts/echarts.min.js"></script>
<script type="text/javascript">


    layui.use(['form', 'table', 'element', 'layer', 'vip_tab'], function () {
        // 打开选项卡
        $('.my-nav-btn').on('click', function () {
            if ($(this).attr('data-href')) {
                vipTab.add($(this), '<i class="layui-icon">' + $(this).find("button").html() + '</i>' + $(this).find('p:last-child').html(), $(this).attr('data-href'));
            }
        });
        var table = layui.table, form = layui.form;
        var loading = layer.load();
        $.ajax({
            url: '../ajax.php?mod=user_applist',
            type: 'POST',
            dataType: 'html',
            data: '',
            success: function (data) {
                layer.close(loading);
                $('#applist').html('<option></option><option value="0">所有应用</option>'+data);
                form.render('select');
            },
            error: function (data) {
                layer.close(loading);
                layer.msg('请求失败' + data);
            }
        })

        table.render({
            elem: '#bclist'
            , url: '../ajax.php?mod=getbclist'
            , cellMinWidth: 130
            , cols: [[
                {field: 'ID', title: 'ID', width: 60}
                , {field: 'obj', title: '对象'}
                , {field: 'app', title: '应用'}
                , {field: 'time', title: '添加时间'}
                , {field: 'reason', title: '云黑理由'}
                , {toolbar: '#barDemo', title: '操作', width: 240}
            ]]
            , page: true
        });

        table.on('tool', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定要删除这个账号('+data.obj+')？', function (index) {
                    $.ajax({
                        url: '../ajax.php?mod=delbc',
                        type: 'POST',
                        dataType: 'json',
                        data: 'id=' + data.ID,
                        success: function (data) {
                            //layer.close(loading);
                            obj.del();
                            layer.msg(data.msg);
                        },
                        error: function (data) {
                            //layer.close(loading);
                            layer.msg('请求失败' + data);
                        }
                    });
                    layer.close(index);
                });
            }
        });


        form.on('submit', function (data) {
            var loading = layer.load();
            $.ajax({
                url: '../ajax.php?mod=addbc',
                type: 'POST',
                dataType: 'json',
                data: 'obj=' + data.field.obj + '&appid=' + data.field.applist + '&reason=' + data.field.reason,
                success: function (data) {
                    layer.close(loading);
                    layer.msg(data.msg);
                    table.reload('bclist', {url: '../ajax.php?mod=getbclist'});
                },
                error: function (data) {
                    layer.close(loading);
                    layer.msg('请求失败' + data);
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });


</script>
</body>
</html>